//
//  STAAlertView.m
//  Staff
//
//  Created by caiyao on 12/3/14.
//
//

#import "STAAlertView.h"

@implementation STAAlertView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)settitle:(NSString *)title message:(NSString *)message cancelButton:(NSString *)cancelButtonTitle okButton:(NSString *)okButtonTitle delegate:(id<STAAlertViewDelegate>)delegate {
    
    line.backgroundColor = [UIColor colorWithRed:242/255.0 green:102/255.0 blue:71/255.0 alpha:1];
    
    titleLabel.text = title;
    contentLabel.text = message;
    
    indicator.hidden = YES;
    contentLabel.hidden = NO;


    
    if (okButtonTitle) {
        cancelButton.frame = CGRectMake(self.frame.size.width/2-20-cancelButton.frame.size.width, cancelButton.frame.origin.y, cancelButton.frame.size.width, 30);
        okButton.hidden = NO;
        okButton.frame = CGRectMake(self.frame.size.width/2+10, okButton.frame.origin.y, cancelButton.frame.size.width, 30);
        
        okButton.backgroundColor = [UIColor colorWithRed:242/255.0 green:102/255.0 blue:71/255.0 alpha:1];
        [okButton setTitle:okButtonTitle forState:UIControlStateNormal];
    } else {

        cancelButton.frame = CGRectMake(96, okButton.frame.origin.y, cancelButton.frame.size.width, cancelButton.frame.size.height);
        cancelButton.backgroundColor = [UIColor colorWithRed:242/255.0 green:102/255.0 blue:71/255.0 alpha:1];
        [cancelButton setTitle:cancelButtonTitle forState:UIControlStateNormal];
        
        okButton.hidden = YES;
    }
    
    self.delegate = delegate;
    
}

- (void)startDownloadingWithTitle:(NSString *)title cancelButton:(NSString *)cancelButtonTitle delegate:(id<STAAlertViewDelegate>)delegate {
    line.backgroundColor = [UIColor colorWithRed:242/255.0 green:102/255.0 blue:71/255.0 alpha:1];
    titleLabel.text = title;

    cancelButton.frame = CGRectMake(96, okButton.frame.origin.y, cancelButton.frame.size.width, cancelButton.frame.size.height);
    cancelButton.backgroundColor = [UIColor colorWithRed:242/255.0 green:102/255.0 blue:71/255.0 alpha:1];
    [cancelButton setTitle:cancelButtonTitle forState:UIControlStateNormal];
    
    indicator.hidden = NO;
    [indicator startAnimating];
    
    cancelButton.hidden = NO;
    
    okButton.hidden = YES;
    contentLabel.hidden = YES;
    
    self.delegate = delegate;
}

- (IBAction)okAction:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(okButtonClicked)]) {
        [_delegate okButtonClicked];
    }
}

- (IBAction)cancelAction:(id)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(cancelButtonClicked)]) {
        [_delegate cancelButtonClicked];
    }
}

@end
